package cn.com.backstage.controller.base;

import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Date;
import java.text.SimpleDateFormat;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import cn.com.api.entity.ApiT_shops_apply;

import cn.com.api.service.ApiT_shops_applyService;

import cn.com.util.*;
import cn.com.util.*;


public class T_shops_applyBaseController {

	private static Logger logger = Logger.getLogger(T_shops_applyBaseController.class);
	
	@Autowired
	private ApiT_shops_applyService apiT_shops_applyService;
	
	/**
	 * 列表
	 * @return
	 */
	@RequestMapping(value = "t_shops_apply-list")
	public ModelAndView t_shops_apply_list(HttpServletRequest request, HttpServletResponse response) throws Exception{
		ModelAndView mv = new ModelAndView("forward:/backstage/t_shops_apply_list.jsp");
		
		List<ApiT_shops_apply> t_shops_applys = apiT_shops_applyService.findT_shops_applys();
		mv.addObject("t_shops_applys", t_shops_applys);
		
		return mv;
	}
	
	/**
	 * 进入新增或者编辑页面
	 * @return
	 */
	@RequestMapping(value = "t_shops_apply-add-pre")
	public ModelAndView t_shops_apply_add_pre(HttpServletRequest request, HttpServletResponse response) throws Exception{
		ModelAndView mv = new ModelAndView("forward:/backstage/t_shops_apply_add.jsp");
		//
		if(request.getParameter("id")!=null){
			String id = request.getParameter("id");
			ApiT_shops_apply t_shops_apply = apiT_shops_applyService.findT_shops_applyById(Integer.valueOf(id));
			mv.addObject("t_shops_apply",t_shops_apply);
		}
		return mv;
	}

	/**
	 *新增或者编辑
	 * @return
	 */
	@RequestMapping(value = "t_shops_apply-add")
	public void t_shops_apply_add(HttpServletRequest request, HttpServletResponse response) throws Exception{
		
		String shop_id = request.getParameter("shop_id");
		String shop_name = request.getParameter("shop_name");
		String shop_type = request.getParameter("shop_type");
		String day_avg_money = request.getParameter("day_avg_money");
		String sign_time = request.getParameter("sign_time");
		String create_time = request.getParameter("create_time");
		String money = request.getParameter("money");
		String bd_user = request.getParameter("bd_user");
		String status = request.getParameter("status");
		String remark = request.getParameter("remark");
		
		Map<String,Object> map = new HashMap<String,Object>();
		String id = request.getParameter("id");
		//add
		if(id==null || (id.trim()).equals("")){
			ApiT_shops_apply t_shops_apply = new ApiT_shops_apply();
            /*
		    t_shops_apply.setId(id);
		    t_shops_apply.setShop_id(shop_id);
		    t_shops_apply.setShop_name(shop_name);
		    t_shops_apply.setShop_type(shop_type);
		    t_shops_apply.setDay_avg_money(day_avg_money);
		    t_shops_apply.setSign_time(sign_time);
		    t_shops_apply.setCreate_time(create_time);
		    t_shops_apply.setMoney(money);
		    t_shops_apply.setBd_user(bd_user);
		    t_shops_apply.setStatus(status);
		    t_shops_apply.setRemark(remark);
	        */
			apiT_shops_applyService.insertT_shops_apply(t_shops_apply);
		}
		//edit
		else{
			ApiT_shops_apply t_shops_apply = apiT_shops_applyService.findT_shops_applyById(Integer.valueOf(id));
	        /*
		    t_shops_apply.setId(id);
		    t_shops_apply.setShop_id(shop_id);
		    t_shops_apply.setShop_name(shop_name);
		    t_shops_apply.setShop_type(shop_type);
		    t_shops_apply.setDay_avg_money(day_avg_money);
		    t_shops_apply.setSign_time(sign_time);
		    t_shops_apply.setCreate_time(create_time);
		    t_shops_apply.setMoney(money);
		    t_shops_apply.setBd_user(bd_user);
		    t_shops_apply.setStatus(status);
		    t_shops_apply.setRemark(remark);
			*/
			apiT_shops_applyService.updateT_shops_apply(t_shops_apply);
		}
		//
		map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
		map.put(Utils.MESSAGE, "添加成功！");
		response.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();
		out.print(JsonUtil.object2json(map));
		out.close();
	}
	
	/**
	 *删除
	 * @return
	 */
	@RequestMapping(value = "t_shops_apply-delete")
	public void t_shops_apply_delete(HttpServletRequest request, HttpServletResponse response) throws Exception{
		
		Map<String,Object> map = new HashMap<String,Object>();
		String id = request.getParameter("id");
		
		//delete
		int ret_i =	apiT_shops_applyService.deleteT_shops_apply(Integer.valueOf(id));
		
		//
		if(ret_i > 0){
			map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
			map.put(Utils.MESSAGE, "删除成功！");
		}
		response.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();
		out.print(JsonUtil.object2json(map));
		out.close();
	}
	
}



